package com.fly.show.text;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/text")
public class TextController
{
    @Autowired
    TextService textService;
    
    @GetMapping({"/", "/index"})
    public String index(String name, Model model)
    {
        model.addAttribute("text", textService.getText());
        return "text/index";
    }
    
    @PostMapping("/submit")
    public String upload(String text)
    {
        textService.setText(text);
        return "redirect:/text/index";
    }
}
